using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQOPTION
    {
        public DataRow Convert2QOPTION(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQOPTION(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QOPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QOPGKREGEL"] = " ".PadRight(8 ); 
         dwReturn["QOPOPTION"] = " ".PadRight(8 ); 
         dwReturn["QOPAENZL"] = " ".PadRight(0 ); 
         dwReturn["QOPAENB"] = " ".PadRight(8 ); 
         dwReturn["QOPAEND"] = " ".PadRight(0 ); 
         dwReturn["QOPNEUB"] = " ".PadRight(8 ); 
         dwReturn["QOPNEUD"] = " ".PadRight(0 ); 
         dwReturn["QOPBEZ"] = " ".PadRight(30 ); 
         dwReturn["QOPSTATUS"] = " ".PadRight(1 ); 
         dwReturn["QOPNRVGUETPKT"] = " ".PadRight(0 ); 
         dwReturn["QOPRVGUETPKT"] = " ".PadRight(0 ); 
         dwReturn["QOPRSTRKF"] = " ".PadRight(1 ); 
         dwReturn["QOPRSTRKFVG"] = " ".PadRight(1 ); 
         dwReturn["QOPFNVGUETPKT"] = " ".PadRight(0 ); 
         dwReturn["QOPFVGUETPKT"] = " ".PadRight(0 ); 
         dwReturn["QOPFSTRKF"] = " ".PadRight(1 ); 
         dwReturn["QOPFSTRKFVG"] = " ".PadRight(1 ); 
         dwReturn["QOPSTKAUSR"] = " ".PadRight(1 ); 
         dwReturn["QOPFSCHLN"] = " ".PadRight(3 ); 
         dwReturn["QOPFSCHLSCHN"] = " ".PadRight(3 ); 
         dwReturn["QOPFSCHLVERL"] = " ".PadRight(3 ); 
         dwReturn["QOPFILLER"] = " ".PadRight(45 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQOPTION(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQOPTION(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQOPTION(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQOPTION(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQOPTION(dwLocal, ITXDBVERSION);
            }
            UpdateQOPTION(dwLocal);
        }
        public void InsertQOPTION(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QOPTION(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQOPTION(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QOPTION WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QOPTION  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QOPTION";
            Return = Result;
            return Return;
        }
        public void DeleteQOPTION(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QOPTION   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQOPTION(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QOPTION SET "
                    +"QOPMANDANT= :QOPMANDANT,"
                    +"QOPGKREGEL= :QOPGKREGEL,"
                    +"QOPOPTION= :QOPOPTION,"
                    +"QOPAENZL= :QOPAENZL,"
                    +"QOPAENB= :QOPAENB,"
                    +"QOPAEND= :QOPAEND,"
                    +"QOPNEUB= :QOPNEUB,"
                    +"QOPNEUD= :QOPNEUD,"
                    +"QOPBEZ= :QOPBEZ,"
                    +"QOPSTATUS= :QOPSTATUS,"
                    +"QOPNRVGUETPKT= :QOPNRVGUETPKT,"
                    +"QOPRVGUETPKT= :QOPRVGUETPKT,"
                    +"QOPRSTRKF= :QOPRSTRKF,"
                    +"QOPRSTRKFVG= :QOPRSTRKFVG,"
                    +"QOPFNVGUETPKT= :QOPFNVGUETPKT,"
                    +"QOPFVGUETPKT= :QOPFVGUETPKT,"
                    +"QOPFSTRKF= :QOPFSTRKF,"
                    +"QOPFSTRKFVG= :QOPFSTRKFVG,"
                    +"QOPSTKAUSR= :QOPSTKAUSR,"
                    +"QOPFSCHLN= :QOPFSCHLN,"
                    +"QOPFSCHLSCHN= :QOPFSCHLSCHN,"
                    +"QOPFSCHLVERL= :QOPFSCHLVERL,"
                    +"QOPFILLER= :QOPFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QOPMANDANT", OracleType.NVarChar).Value = dwData["QOPMANDANT"].ToString(); 
          or1.Parameters.Add("QOPGKREGEL", OracleType.NVarChar).Value = dwData["QOPGKREGEL"].ToString(); 
          or1.Parameters.Add("QOPOPTION", OracleType.NVarChar).Value = dwData["QOPOPTION"].ToString(); 
          or1.Parameters.Add("QOPAENZL", OracleType.NVarChar).Value = dwData["QOPAENZL"].ToString(); 
          or1.Parameters.Add("QOPAENB", OracleType.NVarChar).Value = dwData["QOPAENB"].ToString(); 
          or1.Parameters.Add("QOPAEND", OracleType.NVarChar).Value = dwData["QOPAEND"].ToString(); 
          or1.Parameters.Add("QOPNEUB", OracleType.NVarChar).Value = dwData["QOPNEUB"].ToString(); 
          or1.Parameters.Add("QOPNEUD", OracleType.NVarChar).Value = dwData["QOPNEUD"].ToString(); 
          or1.Parameters.Add("QOPBEZ", OracleType.NVarChar).Value = dwData["QOPBEZ"].ToString(); 
          or1.Parameters.Add("QOPSTATUS", OracleType.NVarChar).Value = dwData["QOPSTATUS"].ToString(); 
          or1.Parameters.Add("QOPNRVGUETPKT", OracleType.NVarChar).Value = dwData["QOPNRVGUETPKT"].ToString(); 
          or1.Parameters.Add("QOPRVGUETPKT", OracleType.NVarChar).Value = dwData["QOPRVGUETPKT"].ToString(); 
          or1.Parameters.Add("QOPRSTRKF", OracleType.NVarChar).Value = dwData["QOPRSTRKF"].ToString(); 
          or1.Parameters.Add("QOPRSTRKFVG", OracleType.NVarChar).Value = dwData["QOPRSTRKFVG"].ToString(); 
          or1.Parameters.Add("QOPFNVGUETPKT", OracleType.NVarChar).Value = dwData["QOPFNVGUETPKT"].ToString(); 
          or1.Parameters.Add("QOPFVGUETPKT", OracleType.NVarChar).Value = dwData["QOPFVGUETPKT"].ToString(); 
          or1.Parameters.Add("QOPFSTRKF", OracleType.NVarChar).Value = dwData["QOPFSTRKF"].ToString(); 
          or1.Parameters.Add("QOPFSTRKFVG", OracleType.NVarChar).Value = dwData["QOPFSTRKFVG"].ToString(); 
          or1.Parameters.Add("QOPSTKAUSR", OracleType.NVarChar).Value = dwData["QOPSTKAUSR"].ToString(); 
          or1.Parameters.Add("QOPFSCHLN", OracleType.NVarChar).Value = dwData["QOPFSCHLN"].ToString(); 
          or1.Parameters.Add("QOPFSCHLSCHN", OracleType.NVarChar).Value = dwData["QOPFSCHLSCHN"].ToString(); 
          or1.Parameters.Add("QOPFSCHLVERL", OracleType.NVarChar).Value = dwData["QOPFSCHLVERL"].ToString(); 
          or1.Parameters.Add("QOPFILLER", OracleType.NVarChar).Value = dwData["QOPFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
